from logging import threading

class MemoryCache(object):
    
    __bitmaps = {}
    __touched = {}
    __lock = threading.Lock()

    def __init__(self):
        '''
        MemoryCache
        '''
    
    def add(self, key, bitmap):
        self.__lock.acquire()
        try:
            self.__bitmaps[key] = bitmap
        finally:
            self.__lock.release()
    
    def remove(self, key):
        self.__lock.acquire()
        try:
            try:
                del(self.__bitmaps[key])
            except KeyError:
                print("Key not found nothing removed")
        finally:
            self.__lock.release()
                
    def find(self, key):
        self.__lock.acquire()
        try:
            if (key in self.__bitmaps):
                image = self.__bitmaps[key]
            else:
                image = None
        finally:
            self.__lock.release()
        return image

    def containsKey(self, key):
        return self.__bitmaps.has_key(key)